const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const connect = require("./connect");
const dbConfig = require('../config/db');

const dumallDB = connect.openDB(dbConfig.db);

// 商品表结构
let productSchema = new Schema({
    "productId": String,
    "productName": String,
    "salePrice": Number,
    "productImg": String,
})

// 用户表结构
let userSchema = new Schema({
    "userId": String,
    "userName": String,
    "userPwd": String,
    "orderList": Array,
    "cartList": [{
        "productId": String,
        "productName": String,
        "salePrice": String,
        "productImage": String,
        "productNum": String,
        "checked": String // 是否选中 1:选中  0:未选中
    }],
    "addressList": [{
        "addressId": String,
        "userName": String,
        "streetName": String,
        "postCode": String,
        "tel": String,
        "isDefault": Boolean,
    }],
})

module.exports = {
    Goods: dumallDB.model("Good", productSchema),
    Users: dumallDB.model("User", userSchema),
}